package com.yuwubao.uav.tool.service.impl;

import com.yuwubao.framework.bean.PageData;
import com.yuwubao.uav.tool.mapper.OrganizationMapper;
import com.yuwubao.uav.tool.service.OrganizationService;
import com.yuwubao.uav.tool.util.StringUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 */
@Service
public class OrganizationServiceImpl implements OrganizationService {

    private static final Logger logger = LogManager.getLogger(OrganizationServiceImpl.class.getName());

    @Resource
    private OrganizationMapper organizationMapper;

    @Override
    public void deleteOrganization(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    organizationMapper.deleteOrganization(pageData);

                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void updateOrganization(PageData pageData) throws Exception {
        try{
            organizationMapper.updateOrganization(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void disableOrEnableOrganization(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    organizationMapper.disableOrEnableOrganization(pageData);

                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void addOrganization(PageData pageData) throws Exception {
        try{
            organizationMapper.addOrganization(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }

    @Override
    public List<PageData> listOrganization(PageData pageData) throws Exception {
        try{
            return organizationMapper.listOrganization(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return null;
    }
    @Override
    public List<PageData> listOrganizationAll(PageData pageData) throws Exception {
        try{
            return organizationMapper.listOrganizationAll(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return null;
    }
    @Override
    public int listOrganizationCount(PageData pageData) throws Exception {
        try{
            return organizationMapper.listOrganizationCount(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return 0;
    }

    //机构

    @Override
    public void deleteOrgJg(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    organizationMapper.deleteOrgJg(pageData);

                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void updateOrgJg(PageData pageData) throws Exception {
        try{
            organizationMapper.updateOrgJg(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void disableOrEnableOrgJg(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    organizationMapper.disableOrEnableOrgJg(pageData);

                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void addOrgJg(PageData pageData) throws Exception {
        try{
            organizationMapper.addOrgJg(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }

    @Override
    public List<PageData> listOrgJg(PageData pageData) throws Exception {
        try{
            return organizationMapper.listOrgJg(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return null;
    }
    @Override
    public List<PageData> listOrgJgAll(PageData pageData) throws Exception {
        try{
            return organizationMapper.listOrgJgAll(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return null;
    }
    @Override
    public int listOrgJgCount(PageData pageData) throws Exception {
        try{
            return organizationMapper.listOrgJgCount(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return 0;
    }

    //领导

    @Override
    public void deleteOrgLeader(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    organizationMapper.deleteOrgLeader(pageData);

                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void updateOrgLeader(PageData pageData) throws Exception {
        try{
            organizationMapper.updateOrgLeader(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void disableOrEnableOrgLeader(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    organizationMapper.disableOrEnableOrgLeader(pageData);

                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void addOrgLeader(PageData pageData) throws Exception {
        try{
            organizationMapper.addOrgLeader(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }

    @Override
    public List<PageData> listOrgLeader(PageData pageData) throws Exception {
        try{
            return organizationMapper.listOrgLeader(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return null;
    }
    @Override
    public List<PageData> listOrgLeaderAll(PageData pageData) throws Exception {
        try{
            return organizationMapper.listOrgLeaderAll(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return null;
    }
    @Override
    public int listOrgLeaderCount(PageData pageData) throws Exception {
        try{
            return organizationMapper.listOrgLeaderCount(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return 0;
    }


}
